//
//  SouSuoViewController.m
//  QT
//
//  Created by 甘世清 on 2025/1/1.
//

#import "SouSuoViewController.h"
#import "SeoSouTopView.h"
#import "SynthesisViewController.h"
#import "XiangYiViewController.h"
#import "PeopleListViewController.h"
@interface SouSuoViewController ()<UITextFieldDelegate>
@property (nonatomic , strong) SynthesisViewController * zhVC;
@property (nonatomic , strong) XiangYiViewController * xyVC;
@property (nonatomic , strong) PeopleListViewController * peopleVC;
@property (nonatomic , strong) SeoSouTopView * topView;
@end

@implementation SouSuoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self SQ_UIViewForSelfView];
    // Do any additional setup after loading the view.
}

- (void)SQ_UIViewForSelfView{
    self.tabContentView.interceptRightSlideGuetureInFirstPage = YES;
    self.tabBar.leadingSpace = 20;
    self.tabBar.itemTitleColor = [UIColor grayColor];
    self.tabBar.itemTitleSelectedColor =  UIColor.blackColor;
    self.tabBar.itemTitleSelectedFont = FONT_MEDIUM(18);
    self.tabBar.itemTitleFont = FONT_MEDIUM(16);
    self.tabBar.itemFontChangeFollowContentScroll = YES;
    self.tabBar.indicatorScrollFollowContent = YES;
    self.tabBar.indicatorColor = UIColor.blackColor;
    [self.tabBar setIndicatorWidthFitTextAndMarginTop:36 marginBottom:6 widthAdditional:0 tapSwitchAnimated:YES];
    self.tabContentView.backgroundColor = UIColor.clearColor;
    self.tabContentView.loadViewOfChildContollerWhileAppear = YES;
    [self.tabContentView setContentScrollEnabled:YES tapSwitchAnimated:NO];
    [self.tabBar setScrollEnabledAndItemFitTextWidthWithSpacing:10 minWidth:70];
    [self setTabBarFrame:CGRectMake(0,TopHeight, SCREEN_WIDETH, 44)
        contentViewFrame:CGRectMake(0, TopHeight+44, SCREEN_WIDETH, SCREEN_HEIGHT-FootHeight-TopHeight-50-44)];
    
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = SQHexColor(@"#000000", 0.2);
    [self.tabBar addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.tabBar);
            make.right.equalTo(self.tabBar.mas_right);
            make.height.mas_equalTo(0.6);
            make.bottom.equalTo(self.tabBar.mas_bottom).offset(-4);
    }];
   
//    [self.tabContentView setHeaderView:self.topView
//                                 style:YPTabHeaderStyleStretch
//                          headerHeight:TopHeight+20
//                          tabBarHeight:44
//                 tabBarStopOnTopHeight:TopHeight+20
//                                 frame:CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT-FootHeight-44)];
    
    
    self.viewControllers = [[NSMutableArray alloc]initWithObjects:self.zhVC,self.peopleVC,self.xyVC, nil];
    self.tabContentView.containerTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tabContentView.containerTableView.backgroundColor = UIColor.whiteColor;
    
    [self.view addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.view);
            make.height.mas_equalTo(TopHeight);
    }];
}

- (void)textFieldDidChange:(UITextField *)textField
{
    self.xyVC.searchString = textField.text;
    self.peopleVC.searchString = textField.text;
    self.zhVC.searchString = textField.text;
    UITextRange *rang = textField.markedTextRange;
    if(rang !=nil) {
      return;
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.view endEditing:YES];
    [self.xyVC SQ_Header];
    [self.peopleVC SQ_Header];
    [self.zhVC SQ_Header];
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)contentViewDidScroll:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
}
 

- (void)tabContentView:(YPTabContentView *)tabConentView didChangedContentOffsetY:(CGFloat)offsetY {
    [self.view endEditing:YES];
}
- (SeoSouTopView *)topView{
    if (!_topView) {
        _topView = [[SeoSouTopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, TopHeight)];
        [_topView.nameTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        _topView.nameTextField.delegate = self;
    }
    return _topView;
}

- (SynthesisViewController *)zhVC{
    if (!_zhVC) {
        _zhVC = [[SynthesisViewController alloc]init];
        _zhVC.yp_tabItemTitle = SQNSLocalString(@"综合");
    }
    return _zhVC;
}
- (PeopleListViewController *)peopleVC{
    if (!_peopleVC) {
        _peopleVC = [[PeopleListViewController alloc]init];
        _peopleVC.yp_tabItemTitle = SQNSLocalString(@"用户");
    }
    return _peopleVC;
}
- (XiangYiViewController *)xyVC{
    if (!_xyVC) {
        _xyVC = [[XiangYiViewController alloc]init];
        _xyVC.yp_tabItemTitle = SQNSLocalString(@"相易");
    }
    return _xyVC;
}

@end
